﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/HomeSite.Master" Inherits="System.Web.Mvc.ViewPage<IEnumerable<TimeTableManagement.Entities.Tb_Config>>" %>

<%@ Register Assembly="DevExpress.Web.v11.1, Version=11.1.7.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a"
    Namespace="DevExpress.Web.ASPxRoundPanel" TagPrefix="dx" %>

<%@ Register assembly="DevExpress.Web.v11.1, Version=11.1.7.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" namespace="DevExpress.Web.ASPxPanel" tagprefix="dx" %>

<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
<div id="dialog" title="Edit Term">
        <% using (Html.BeginForm("Edit", "Term", FormMethod.Post))
           {%>
           <div class="editor-label">
                <%: Html.Label("Displayword") %>
            </div>
            <div class="editor-field">
                <input id="displayword1" name="displayword" type="text" value="">
            </div>
            <div class="editor-label">Start
            </div>
            <div class="editor-field">
                <input id="start" name="start" type="text" value="">
            </div>
            <div class="editor-label">End
            </div>
            <div class="editor-field">
                <input id="end" name="end" type="text" value="">
            </div>
            <input id="idedit" name="id" type="hidden" value=""/>
            <p><input type="submit" value="Save" /></p>
            
         <% } %>
</div>

<div id="newterm" title="Add New">
        <% using (Html.BeginForm("Create", "Term", FormMethod.Post))
           {%>
            <div class="editor-label">
                <%: Html.Label("Name") %>
            </div>
            <div class="editor-field">
                <input id="displayword" name="displayword" type="text" value="" onkeypress="updatekeyword()">
            </div>

            <div class="editor-label">
                <%: Html.Label("Start") %>
            </div>
            <div class="editor-field">
                <input id="start" name="start" type="text" value="">
            </div>

            <div class="editor-label">
                <%: Html.Label("End") %>
            </div>
            <div class="editor-field">
                <input id="end" name="end" type="text" value="">
            </div>
            <input id="keyword" name="keyword" type="hidden" value=" "/>
            <input id="option" name="option" type="hidden" value="term"/>
            
            <%--Tao JS, khi click vao Save, tao keyword ngau nhien dua vao displayword--%>
            <input id="control" name="control" type="hidden" value="Term" />
            <input id="action" name="action" type="hidden" value="Index" />
            <p><input type="submit" value="Save" /></p>
         <% } %>

</div>

<div id="Div1" title="Delete Term">
        <% using (Html.BeginForm("Delete", "Term", FormMethod.Post))
           {%>
           <div class="editor-label">
                <h2>Are you sure delete this term?</h2>
            </div>
            <div class="editor-field">
                 <h4><span>Term: </span></h4>
                 <input id="Hidden1" name="id" type="hidden" value=""/>
            </div>
            <p><input type="submit" value="OK" /></p>
            
         <% } %>
</div>

<%--Can JS: khi click vao EDIT cua moi dong, thi mo form dialog voi cac gia tri tuong ung--%>
    <dx:ASPxRoundPanel ID="ASPxRoundPanel1" runat="server" Width="100%" 
        CssFilePath="~/App_Themes/Aqua/{0}/styles.css" CssPostfix="Aqua" 
        GroupBoxCaptionOffsetY="-28px" 
        SpriteCssFilePath="~/App_Themes/Aqua/{0}/sprite.css">
        <ContentPaddings Padding="14px" />
        <PanelCollection>
<dx:PanelContent runat="server" SupportsDisabledAttribute="True">
<table style="width:100%" id="t1" class="example table-autosort
 table-autofilter table-autopage:20 
 table-stripeclass:alternate 
 table-page-number:t1page table-page-count:t1pages 
 table-filtered-rowcount:t1filtercount 
 table-rowcount:t1allcount">
   <thead>
    <tr>
        <th>
            Code
        </th>
        <th>
            Term
        </th>
        <th>
            Start
        </th>
        <th>
            End
        </th>
        <th></th>
    </tr>
</thead>
<tbody>
<% foreach (var item in Model)
   { %>
   <tr>
        <td>
            <%: Html.DisplayFor(modelItem => item.keyword) %>
        </td>
        <td>
            <%: Html.DisplayFor(modelItem => item.displayword) %>
        </td>
        <td>
            <%: new TimeTableManagement.Controllers.Term().getTermStart(item.id) %>
        </td>
        <td>
            <%: new TimeTableManagement.Controllers.Term().getTermEnd(item.id) %>
        </td>
        <td>
            <%--<%: Html.ActionLink("Edit", "Edit", new { id=item.id }) %> |--%>
            <a id="<%:item.id %>" displaykeyword="<%:item.displayword %>" 
                start="<%: new TimeTableManagement.Controllers.Term().getTermStart(item.id) %>"
                endding="<%: new TimeTableManagement.Controllers.Term().getTermEnd(item.id) %>"
                href="#" onclick="putdisplaykeyword(this); jQuery('#dialog').dialog('open'); return false">Edit</a> |
            <a href="#" onclick="putdisplaykeyword(this); jQuery('#Div1').dialog('open'); return false">Delete</a>
        </td>
    </tr>
<% } %>
</tbody>
<tfoot>
	<tr>
		<td class="table-page:previous" style="cursor:pointer; text-align:right"><img src="../../Content/iconprevious.png" /></td>
		<td style="text-align:center" colspan="3" class="table-page-number:t1page">Page <span id="t1page"></span>&nbsp;of&nbsp;<span id="t1pages"></span></td>
        <td class="table-page:next" style="cursor:pointer; text-align:left"> <img src="../../Content/iconnext.png" /></td>
	</tr>
</tfoot>
</table>
<a href="#" onclick="jQuery('#newterm').dialog('open'); return false">Add Term</a>
</dx:PanelContent>
</PanelCollection>
    </dx:ASPxRoundPanel>
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="HeadContent" runat="server">
<script>
    function putdisplaykeyword($item) {
        document.getElementById('idedit').value = $item.id;
        document.getElementById('displayword1').value = $item.getAttribute("displaykeyword");
        document.getElementById('start').value = $item.getAttribute("start");
        document.getElementById('end').value = $item.getAttribute("endding");
    }
</script>

<script>
    function updatekeyword() {
        $temp = document.getElementById('displayword').value;
        document.getElementById('keyword').value = $temp.replace(/ /g, '-').substr(0, 10);
        return true;
    }
</script>
<script type="text/javascript">
    $(function () {
        $("#dialog").dialog({
            bgiframe: true,
            height: 250,
            width: 400,
            modal: true,
            autoOpen: false,
            resizable: false
        })
    });
        
    </script>
<script type="text/javascript">
    $(function () {
        $("#Div1").dialog({
            bgiframe: true,
            height: 200,
            width: 400,
            modal: true,
            autoOpen: false,
            resizable: false
        })
    });
        
    </script>
    <script type="text/javascript">
        $(function () {
            $("#newterm").dialog({
                bgiframe: true,
                height: 250,
                width: 400,
                modal: true,
                autoOpen: false,
                resizable: false
            })
        });
        
    </script>
</asp:Content>

<asp:Content ID="Content3" ContentPlaceHolderID="leftmenu" runat="server">
</asp:Content>

<asp:Content ID="Content4" ContentPlaceHolderID="menuright" runat="server">
</asp:Content>

<asp:Content ID="Content5" ContentPlaceHolderID="Footer" runat="server">
</asp:Content>
